//
//  CYOAuthViewController.swift
//  MySina
//
//  Created by mac on 2017/1/17.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit

class CYOAuthViewController: UIViewController {
    override func loadView() {
        view = webView
        
        let urlString = "https://api.weibo.com/oauth2/authorize?client_id=\(APPKEY)&redirect_uri=\(REDIRECT_URI)"
        
        let url = URL(string: urlString)
        
        guard let u = url else {
            return
        }
        
        let request = URLRequest(url: u)
        
        webView.loadRequest(request)
        
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white
        setupNavigationBar()
    }

    private func setupNavigationBar() {

        title = "微博登录"
        //设置左侧按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: nil, title: "取消", target: self, action: #selector(cancelClick))
        //设置右侧按钮
        navigationItem.rightBarButtonItem = UIBarButtonItem(imgName: nil, title: "自动填充", target: self, action: #selector(oauthClick))
        
    }
    
    //懒加载webView
    private lazy var webView: UIWebView = {
        let view = UIWebView()
        return view
    }()
    
    //按钮监听事件
    @objc private func cancelClick() {
        dismiss(animated: false, completion: nil)
    }
    
    @objc private func oauthClick() {
        print("自动填充")
    }
    
    
}
